import java.util.Scanner;

public class C_1551 {
    static int max = -1;
    static int mm;
    static boolean isOne = true;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] value = new int[n];
        for (int i = 0; i < n; i++) {
            value[i] = sc.nextInt();
        }
        if (n/2<m){
            System.out.println("Error!");
            return;
        }
        mm = m;
        dfs(value,m,0,0);
        System.out.println(max);
    }
    static void dfs(int[] value,int m ,int at,int num){
        if (at-2>=value.length||(isOne&&(at-1>=value.length))){
            return;
        }
        if (m==0){
            max = Math.max(num,max);
            return;
        }
        for (int i = at; i < value.length; i++) {
            if(m==mm&&i!=0)
                isOne = false;
            num+=value[i];
                at = i;
            dfs(value,m-1,at+2,num);
            num-=value[i];
        }
    }
}